package mycoffee.order.task;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

public class UploadInvoiceTask extends AsyncTask<String, Integer, Boolean> {
	private static final String HTTPSERVER = "http://mycoffee-v02.tt-tech.vn/manage/manage-channel/syncserver";
	
    protected Boolean doInBackground(String... jsonString) {
    	return this.postData(jsonString[0]);
    }

    protected void onProgressUpdate(Integer... progress) {
//        setProgressPercent(progress[0]);
    }

    protected void onPostExecute(Boolean result) {
//        showDialog("Invoice uploaded!");
    }

    private boolean postData(String data) {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(HTTPSERVER);

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("order", data));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            
            return true;
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        	return false;
        } catch (IOException e) {
            // TODO Auto-generated catch block
        	return false;
        }
    }
}